<template>
  <div class="radio-detail">
    <div class="radio-title">
      <div @click="backToRadio" class="position-f pl-3" style="padding-top: 5.25rem;">
        <i class="iconfont" style="font-size: 2rem;color: #FFFFFF;">&#xe64f;</i>
      </div>
      <img :src="coverUrl" width="100%">
      <div class="radio-title-name text-weight-6">{{radioName}}</div>
    </div>
    <div class="radio-main">
      <p class="text-l px-4 text-weight-6">节目单</p>
      <ul class="pt-1 px-4">
      	<li v-for="(item,index) in radioProgramList" :key="item.id" class="d-flex pb-3"
        @click="getRadioMusicId(item.songId,item.name)">
          <div class="d-flex flex-nowrap pl-3 jc-between">
            <div class="text-weight-6 songindex">{{index+1}}</div>
            <div class="w100 text-s pl-2 iconfont">&#xe616; {{item.name}}</div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
  import { mapMutations } from 'vuex'
  export default {
    data() {
      return{
        radioName: '',
        coverUrl:'',
        radioProgramList:[]
      }
    },
    created() {
      this.getRadioPrograms()
    },
    methods: {
      ...mapMutations(['SET_MUSIC_URL','SET_MUSIC_NAME']),
      //获取电台
      async getRadioPrograms() {
        const {
          data: res
        } = await this.$http.get('/dj/program', {
          params: {
            rid: this.$route.query.id
          }
        })
        this.radioName = this.$route.query.name
        this.coverUrl = res.programs[0].coverUrl
        this.radioProgramList = res.programs.map(item => ({
          name: item.name,
          songId: item.mainSong.id
        }))
      },
      async getRadioMusicId(id,name) {
        const {data: res} = await this.$http.get('/song/url?id='+id)
        this.SET_MUSIC_URL(res.data[0].url)
        this.SET_MUSIC_NAME(name)
      },
      backToRadio(){
        this.$router.push('/radio')
      }
    }
  }
</script>

<style lang="scss" scoped>
  .radio-detail{
    width: 100%;
  }
  .radio-title{
    position: absolute;
    width: 100%;
    top: 5rem;
    .radio-title-name{
      position: absolute;
      bottom: 8rem;
      left: 1rem;
      color: #FFFFFF;
      font-size: 1.8rem;
      letter-spacing: 0.2rem;
    }
  }

  .radio-main{
    width: 100%;
    position: absolute;
    top: 25rem;
    background-color: #FFFFFF;
    border-radius: 1rem;
    padding-bottom: 6rem;
  }
  .songindex{
    width: 1rem;
  }
</style>
